import Vue  from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store=new Vuex.Store({
    state:{
        brandList:[
            {id:2,name:'奔驰',ctime:'2020-10-28'},
            {id:1,name:'比亚迪',ctime:'2020-10-28'},


        ]
    },
    mutations:{
        brandAdd(state,name){
            if(state.brandList[0]){
                var id=state.brandList[0].id+1
            }else{
                var id=1
            }
            const obj={id,name,ctime:new Date().toLocaleDateString()}
            state.brandList.unshift(obj)
        },
        brandDel(state,id){
            const index=state.brandList.findIndex(item=>item.id===id)
            state.brandList.splice(index,1)
        }

    }
})
export default store